//
//  XCSMSCountryListCell.m
//  HOLLASMSLoginKit
//
//  Created by Mars on 2019/10/11.
//  Copyright © 2019 mao PengLin. All rights reserved.
//

#import "XCSMSCountryListCell.h"
#import "Config.h"
//#import "UIColor+XCSMSColor.h"
#import "XCSMSTheme.h"

@interface XCSMSCountryListCell()
{
    UILabel *countryFlag;
    UILabel *countryName;
    UILabel *countryLocale;
}

@end
@implementation XCSMSCountryListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    self.backgroundColor = [UIColor clearColor];
    if ([XCSMSTheme sharedTheme].countryListCellHighlightedColor) {
        UIView *highlightedView = [[UIView alloc] init];
        highlightedView.backgroundColor = [XCSMSTheme sharedTheme].countryListCellHighlightedColor;
        self.selectedBackgroundView = highlightedView;
    }
    
    countryFlag = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, 24, 46)];
    countryFlag.textAlignment = NSTextAlignmentLeft;
    if (SMSIsArabic()) {
        countryFlag.frame = CGRectMake(HWScreenWidth - 40, 0, 24, 46);
         countryFlag.textAlignment = NSTextAlignmentRight;
    }
    countryFlag.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:countryFlag];
    
    countryLocale = [[UILabel alloc] initWithFrame:CGRectMake(HWScreenWidth - 66, 0, 50, 46)];
    countryLocale.textAlignment = NSTextAlignmentRight;
    if (SMSIsArabic()) {
        countryLocale.frame = CGRectMake(16, 0, 50, 46);
        countryLocale.textAlignment = NSTextAlignmentLeft;
    }
    countryLocale.textColor = [XCSMSTheme sharedTheme].countryListTextColor;
    countryLocale.font = MediumFont(16);
    [self.contentView addSubview:countryLocale];
    
    CGFloat countryNameWidth = HWScreenWidth - 24 - 50 - 16 - 16 - 16;
    countryName = [[UILabel alloc] initWithFrame:CGRectMake(countryFlag.frame.origin.x + countryFlag.frame.size.width + 8, 0, countryNameWidth, 46)];
    if (SMSIsArabic()) {
        countryName.frame = CGRectMake(countryLocale.frame.origin.x + countryLocale.frame.size.width + 8, 0, countryNameWidth, 46);
    }
    countryName.textAlignment = NSTextAlignmentNatural;
    countryName.textColor = [XCSMSTheme sharedTheme].countryListTextColor;
    countryLocale.font = MediumFont(16);
    [self.contentView addSubview:countryName];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(16, 45, HWScreenWidth - 32, 1)];
    line.backgroundColor = [XCSMSTheme sharedTheme].countryListSeparatorColor;
    [self.contentView addSubview:line];
}
    
-(void)setContent:(XCSMSISOCountry *)model{
    countryFlag.text = model.countryFlag;
    countryLocale.text = model.countryCode;
    countryName.text = model.countryName;
}

@end
